<%--
  Created by IntelliJ IDEA.
  User: Administrator
  Date: 2020\7\13 0013
  Time: 14:39
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
    <script>
        function f1() {
            var user={
                "name":"admin",
                "age":25,
                "gender":"男"
            };
            console.log(user["name"],user['age'],user.gender);
        }

        function f2() {
            var user={
                "name":{"firstName":"李","lastName":"四"},
                "age":25,
                "gender":"男"
            };
            console.log(user["name"]["firstName"],user.name.lastName,user["name"].firstName);
        }

        function f3() {
            var user={"name":"admin","age":24,"edu":"本科"};
            var people={"id":"123","user":user};
            console.log(people.id,people.user.name);
        }

        function f4() {
            var user=[{"name":"admin","age":25},{"phone":"139","age":18}];
            console.log(user[0].name,user[1]["phone"]);
        }

        function f5() {
            var user="{'name':'admin','age':25}";
            console.log(typeof user);
            //把字符串转换成json对象
            user=eval("("+user+")");
            console.log(typeof user);
            //eval('alert("hello")');
            user="{\"name\":\"Make\",\"age\":25}";
            user=JSON.parse(user);
            console.log(typeof user,user.name);


        }
    </script>
</head>
<body>
    <a href="javaScript:;" onclick="f1();">点我</a><br>
    <a href="javaScript:;" onclick="f2();">value本身是json1</a>
    <a href="javaScript:;" onclick="f3();">value本身是json2</a>
    <a href="javaScript:;" onclick="f4();">集合</a>
    <a href="javaScript:;" onclick="f5();">字符串转json对象</a>
</body>
</html>
